package org.jeecg.common.mq.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;

/**
 * TODO:
 *
 * @author Zhang Hao yu
 * @date 2020/12/4 16:51
 */
@Configuration
public class ActiveMQConfig {

    /**
     * TODO: 定义topic模式
     *
     *
     * @author ZhangHaoyu
     * @param connectionFactory
     * @return org.springframework.jms.config.JmsListenerContainerFactory<?>
     */
    @Bean
    public JmsListenerContainerFactory<?> jmsListenerContainerTopic(ConnectionFactory connectionFactory) {
        DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
        bean.setPubSubDomain(true);
        bean.setConnectionFactory(connectionFactory);
        return bean;
    }

    /**
     * TODO: 定义queue模式
     *
     *
     * @author ZhangHaoyu
     * @param connectionFactory
     * @return org.springframework.jms.config.JmsListenerContainerFactory<?>
     */
    @Bean
    public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory  connectionFactory) {
        DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
        bean.setConnectionFactory(connectionFactory);
        return bean;
    }
}